package com.orkasgb.filter;

import cn.dev33.satoken.stp.StpUtil;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;

@Component
public class CustomRequestFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        // 在这里添加自定义的请求处理逻辑
        if (!StpUtil.isLogin() && !request.getRequestURI().equals("/login/doLogin")) {
            throw new RuntimeException("未登录");
        }

        filterChain.doFilter(request, response);
    }
}
